package leetcode.new_wrold;

public class T35 {
    public int searchInsert(int[] nums, int target) {
        return BinarySearch(0,nums.length-1,target,nums);
    }

    private int BinarySearch(int l,int r,int target,int[] nums){
        System.out.println("l="+l+",r="+r);
        if (l>r){
            return l;
        }
        int mid = (l+r)/2;
        if (nums[mid]==target){
            return mid;
        }

        if (target>nums[mid]){
            return BinarySearch(mid+1,r,target,nums);
        }else{
            return BinarySearch(l,mid-1,target,nums);
        }
    }


    public static void main(String[] args) {
        T35 t35 = new T35();
        int i = t35.searchInsert(new int[]{1}, 0);
        System.out.println(i);
    }
}



